package com.example.config;

import com.example.utils.BaseInterceptor;
import com.example.utils.MyInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.filter.OrderedHiddenHttpMethodFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private BaseInterceptor baseInterceptor;

    //拦截器管理
    @Autowired
    private MyInterceptor my;
    //拦截器管理，MyInterceptor.java
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(baseInterceptor);
        //System.out.println(my);
        //拦截全部，但是不包括---
        registry.addInterceptor(my)
        .addPathPatterns("/admin/**","/comments/delete/**","/comments/publish").
        excludePathPatterns();

    }

    //添加视图管理，自动映射转发
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //自动映射,转发到login.html
        registry.addViewController("/toLoginPage").setViewName("login");
        registry.addViewController("/login.html").setViewName("login");

    }


}
